import { useAxiosRef, resultTip } from '../utils/request';
import { onMounted, unref, watch } from 'vue';
import { getway } from '../settings/local';
import createRequest from '../utils/request';

//项目库列表
export function useSpecList() {
    const { reload, axiosRef } = useAxiosRef({
        url: `${getway.value}/swagger-resources`,
        method: "GET"
    })

    onMounted(() => {
        if (!getway.value) return
        reload({})
    })

    return {
        specList: axiosRef,
        reloadSpecList: reload
    }
}


//获取API文档 
export function getDocs(url: string) {
    const _getway = unref(getway)
    return createRequest({
        url: `${_getway}${url}`
    })
}

// 网关被修改， 回调
export function useGetWayChange(cb: (getway: string) => void) {
    watch(getway, (getway) => {
        cb(getway)
    })
}